package com.zyh.method;

import java.util.Scanner;

public class MethodDemo2 {
    public static void main(String[] args) {
        printSum();
        printAvg();
        printReverseArray();
        System.out.println();
        int max = getMax();
        System.out.println("max = " + max);
        int sum = getSum();
        System.out.println("sum = " + sum);
        double mianji = qiuMianJi();
        System.out.println("mianji = " + mianji);
    }

//    打印数组和
    public static void printSum() {
        System.out.println(10 + 20);
    }

//    打印数组平均值
    public static void printAvg() {
        int[] arr = {1, 2, 3, 4, 5};
        double sum = 0.0;
        for (int i = 0; i < arr.length; i++) {
            sum = sum + arr[i];
        }
        System.out.println("数组{1,2,3,4,5}的平均值是：" + sum / arr.length);
    }

//    翻转数组
    public static void printReverseArray() {
        int[] arr = {1, 2, 3, 4, 5};
        for (int start = 0, end = arr.length - 1; start <= end; start++, end--) {
            int temp = arr[start];
            arr[start] = arr[end];
            arr[end] = temp;
        }
        System.out.print("[");
        for (int i = 0; i < arr.length; i++) {
            if (i == arr.length - 1) {
                System.out.print(arr[i]);
            } else {
                System.out.print(arr[i] + ",");
            }
        }
        System.out.print("]");
    }

//    求数组最大值
    public static int getMax() {
        int[] arr = {5, 12, 90, 18, 77, 76, 45, 28, 59, 72};
        int max = arr[0];
        for (int i = 1; i < arr.length; i++) {//从1开始，不用从0开始
            if (arr[i] > max) {
                max = arr[i];
            }
        }
        return max;
    }

//    求两整数和
    public static int getSum() {
        int a = 10, b = 20;
        return a + b;
    }

//     求面积
    public static double qiuMianJi() {
        Scanner input = new Scanner(System.in);
        System.out.println("请输入长：");
        double chang = input.nextDouble();
        System.out.println("请输入宽：");
        double kuan = input.nextDouble();
        return chang * kuan;
    }
}

